package com.data.center.controller;

import com.data.center.dto.OrganizationProfileDTO;
import com.data.center.dto.OrganizationTagRelationshipDTO;
import com.data.center.entity.OrganizationProfile;
import com.data.center.entity.OrganizationTagRelationship;
import com.data.center.exception.ResultBody;
import com.data.center.mapper.OrganizationProfileMapper;
import com.data.center.mapper.OrganizationTagRelationshipMapper;
import com.data.center.service.OrganizationProfileService;
import com.data.center.service.OrganizationTagRelationshipService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Li_Jx
 * @description:
 * @date 2023/12/5 15:05
 */
@RestController
@Slf4j
@RequestMapping("/organizationProfile")
public class OrganizationProfileController {
    @Autowired
    private OrganizationProfileService organizationProfileService;
    @Autowired
    private OrganizationProfileMapper organizationProfileMapper;
    /**
     * @description 一个通用的查询接口
     * @author Li_Jx
     * @Date 2023/11/30 19:41
     */
    @GetMapping("/select")
    public ResultBody select(OrganizationProfileDTO organizationProfileDTO){
        OrganizationProfile organizationProfileFilter = new OrganizationProfile();
        org.springframework.beans.BeanUtils.copyProperties(organizationProfileDTO,organizationProfileFilter);
        List<OrganizationProfile> organizationProfileList = organizationProfileMapper.select(organizationProfileFilter);
        return ResultBody.success(organizationProfileList);
    }

    /**
     * @description 通过id查询对象
     * @author Li_Jx
     * @Date 2023/11/30 19:41
     */
    @GetMapping("/findById")
    public ResultBody findById(String id){
        if(id == null || id.isEmpty()){
            return ResultBody.error("标签id为空");
        }
        OrganizationProfile organizationProfile = organizationProfileMapper.findById(id);
        if(organizationProfile == null){
            return ResultBody.error("未查询到匹配结果");
        }
        return ResultBody.success(organizationProfile);
    }

    /**
     * @description 一个通用的通过id更新接口
     * @author Li_Jx
     * @Date 2023/11/9 19:41
     */
    @PutMapping("/update")
    public ResultBody update(OrganizationProfileDTO organizationProfileDTO){
        OrganizationProfile organizationProfileFilter = new OrganizationProfile();
        org.springframework.beans.BeanUtils.copyProperties(organizationProfileDTO,organizationProfileFilter);
        organizationProfileService.update(organizationProfileFilter);
        return ResultBody.success();
    }
    /**
     * @description 新增标签关系
     * @author Li_Jx
     * @Date 2023/11/30 16:46
     */
    @PostMapping("/insert")
    public ResultBody insert(OrganizationProfileDTO organizationProfileDTO){
        OrganizationProfile organizationProfileFilter = new OrganizationProfile();
        org.springframework.beans.BeanUtils.copyProperties(organizationProfileDTO,organizationProfileFilter);
        organizationProfileService.insert(organizationProfileFilter);
        return ResultBody.success();
    }

    /**
     * @description 通过id删除标签
     * @author Li_Jx
     * @Date 2023/11/21 18:49
     */
    @DeleteMapping("/deleteById")
    public ResultBody deleteById(String id){
        if(id == null || id.isEmpty()){
            return ResultBody.error("标签id为空");
        }
        OrganizationProfile organizationProfile = organizationProfileMapper.findById(id);
        if(organizationProfile == null){
            return ResultBody.error("未查询到匹配结果");
        }
        organizationProfileMapper.deleteById(id);
        return ResultBody.success();
    }
}
